package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.TerminalsReplace;
import com.ruoyi.swla2.service.ITerminalsReplaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 换表明细Controller
 *
 * @author gdqt
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/device/terminalsReplace")
public class TerminalsReplaceController extends BaseController {
    @Autowired
    private ITerminalsReplaceService terminalsReplaceService;

    /**
     * 查询换表明细列表
     */
    @PreAuthorize("@ss.hasPermi('device:terminalsReplace:list')")
    @GetMapping("/list")
    public TableDataInfo list(TerminalsReplace terminalsReplace) {
        startPage();
        List<TerminalsReplace> list = terminalsReplaceService.selectTerminalsReplaceList(terminalsReplace);
        return getDataTable(list);
    }

    /**
     * 导出换表明细列表
     */
    @PreAuthorize("@ss.hasPermi('device:terminalsReplace:export')")
    @Log(title = "换表明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TerminalsReplace terminalsReplace) {
        List<TerminalsReplace> list = terminalsReplaceService.selectTerminalsReplaceList(terminalsReplace);
        ExcelUtil<TerminalsReplace> util = new ExcelUtil<TerminalsReplace>(TerminalsReplace.class);
        util.exportExcel(response, list, "换表明细数据");
    }

    /**
     * 获取换表明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:terminalsReplace:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") String tenantId) {
        return success(terminalsReplaceService.selectTerminalsReplaceByTenantId(tenantId));
    }

    /**
     * 新增换表明细
     */
    @PreAuthorize("@ss.hasPermi('device:terminalsReplace:add')")
    @Log(title = "换表明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TerminalsReplace terminalsReplace) {
        terminalsReplace.setTenantId(this.getTenantId());
        return toAjax(terminalsReplaceService.insertTerminalsReplace(terminalsReplace));
    }

    /**
     * 修改换表明细
     */
    @PreAuthorize("@ss.hasPermi('device:terminalsReplace:edit')")
    @Log(title = "换表明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TerminalsReplace terminalsReplace) {
        return toAjax(terminalsReplaceService.updateTerminalsReplace(terminalsReplace));
    }

    /**
     * 删除换表明细
     */
    @PreAuthorize("@ss.hasPermi('device:terminalsReplace:remove')")
    @Log(title = "换表明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable String[] tenantIds) {
        return toAjax(terminalsReplaceService.deleteTerminalsReplaceByTenantIds(tenantIds));
    }
}
